<?php
class ProtectController extends AppController {

	public $name = 'protect';
	function beforeFilter() {
	    parent::beforeFilter(); 
		$this->C_auth->autoRedirect = false; //For override login
	    $this->C_auth->allowedActions = array('index','closeprotect','protectinfo');

	}
	
	public function index() {	
        $page = Request::get_args('page');
        $url_this = 'http://'.$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
        $tb = array('model' => 'protectright',
 		            'joins' => array(
					    array('type'=>'left','table'=>'shopinfo','conditions'=>array('protectright.shop_id' =>'shopinfo.id')),
					    array('type'=>'left','table'=>'user','conditions'=>array('protectright.user_id' =>'user.id')),						
						),
				    'fields' => array('protectright.*','shopinfo.shop_name','user.username'),
					'conditions' => array('protectright.status' =>2),
					'order' => ' protectright.status desc ',
					'limit' => '10',
					'group' => '',
					'url' => preg_replace("/&page=([^&]+)/","",$url_this),
					'page' => $page,
					'plist' => 6				
				); 
	    $result =  $this->fpage($tb); 		
        $this->set('result',$result);
	}

	public function protectinfo() {
        $page = Request::get_args('page');		
        $order_id = intval(Request::get_args('id'));
        if(!$order_id ) {
            $this->flash("参数错误！", Request::referer()); 
        }		
        $url_this = 'http://'.$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
        $tb = array('model' => 'protectright',
				    'fields' => array('protectright.*'),
					'conditions' => array('order_id' => $order_id),
					'order' => ' protect_date desc ',
					'limit' => '10',
					'group' => '',
					'url' => preg_replace("/&page=([^&]+)/","",$url_this),
					'page' => $page,
					'plist' => 6				
				); 
	    $result =  $this->fpage($tb);				
        $this->set('result',$result);
	}		
	
	public function closeprotect() {
        /* post 数据处理 */
        $pid = intval(Request::get_args('pid'));
        $order_id = intval(Request::get_args('order_id'));
        if(!$pid || !$order_id ) {
            $this->flash("参数错误！", Request::referer()); 
        }
		$query  = array();		
		$query['keyid'] = $order_id;
		$safeData['orderinfo'] = array('protect_status' => 3);				
		$query['set'] = $safeData;		
        if(POP::exe('[@@:UM orderinfo][@@:QU save]',$query)) {
	        /** 添加log */
			$array = array(
				'log_time' => date("Y-m-d H:i:s"),
				'admin_id' => $this->my->id,
			    'admin_name' => $this->my->username,
				'log_info' => "结束维权",
			    'ip_address' => Request::getclientIp(),					
			);
			$safeData['adminlog'] = $array;								
			POP::exe('[@@:UM adminlog][@@:QU save]',$safeData);			
			$query  = array();		
			$query['keyid'] = $pid;
			$safeData['protectright'] = array('status' => 3);				
			$query['set'] = $safeData;		
			POP::exe('[@@:UM protectright][@@:QU save]',$query);			
            $this->flash("结束维权成功！", Request::referer());	
        } else {
            $this->flash("结束维权失败！", Request::referer());			
        }

    }	
	
	
}

?>